/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fr.epsi.montpellier.ejbmodulecrm.heavy.facade;

import fr.epsi.montpellier.ejbmodulecrm.heavy.model.Client;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Clément
 */
@Stateless
public class FacadeClientSessionBean implements FacadeClientBeanRemote, FacadeClientBeanLocal  {

    @PersistenceContext(name="ClientsPU")
    private EntityManager em;
    
    @Override
    public void creerClient(Client c) {
        em.persist(c);
    }

    @Override
    public void modifierClient(Client c) {
        Client cBase = em.find(Client.class, c.getId());
        cBase.setNom(c.getNom());
        cBase.setPrenom(c.getPrenom());
        cBase.setAdresse(c.getAdresse());
        cBase.setCp(c.getCp());
        cBase.setVille(c.getVille());
        cBase.setTelephone(c.getTelephone());
        cBase.setEmail(c.getEmail());
        em.merge(cBase);
    }

    @Override
    public void supprimerClient(Client c) {
        Client client = em.find(c.getClass(), c.getId());
        em.remove(client);
    }

    @Override
    public List<Client> listerClients() {
        Query req = em.createQuery("SELECT c FROM Client c");
        return req.getResultList();
    }

    @Override
    public Client rechercherClientParTel(String telephone) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
